
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>

#include "rp2040.h"
#include "umsg.h"
#include "ttusb_comn.h"
#include "ttusb.h"
#include "dbg_cli.h"


static uint32_t ttt_ticks = 0;

void  SysTick_Handler( void )
{
	ttt_ticks += 1;

	if ( (ttt_ticks % 100) == 0 ) {
		// printf( "tick..\n" );
	}

	return;
}


void  SysTick_P1_Handler( void )
{
	ttt_ticks += 1;

#if 0
	if ( ttt_ticks & 0x2 )  {
		gpio_put( 25, true );
	} else {
		gpio_put( 25, false );
	}
#endif

	return;
}


void HardFault_exception( void )
{
	printf( "hard fault ...\n" );
	while ( 1 )  {
		__asm volatile ( "nop" );
		__asm volatile ( "wfi" );
	}
}



extern void  con_proc_input( void );

int main( void )
{
	int iret;

	/**/
	iret = debug_cli_init();
	printf( "hello, %d\n", iret );

	iret = umsg_init(64);
	printf( "pool, %d\n", iret );

	/* usb auto */
	ttusb_desc_init();
	ttusb_desc_device_vid_pid( 0x2E8A, 0x1013 );
	ttusb_desc_device_str_manu( "TTusb" );
	ttusb_desc_device_str_prod( "Dapk" );
	ttusb_desc_config_power( 0x64 );
	ttusb_desc_interface_add_inp( umsg_inp_cbk );
	ttusb_desc_interface_add_outp( umsg_outp_cbk );
	ttusb_init();

	/**/
	SysTick_Config( 9000000 );

	/**/
	while ( 1 )  {

		con_proc_input();

		/**/
		__WFI();
	}

	return 0;
}


